
<!DOCTYPE html>
<html>
    <head>
        <title>Moon Silver</title>
        <meta charset="UTF-8">    
        <link rel='stylesheet' href='css/nav.css'/>
        <link rel="stylesheet" type="text/css" href="css/headerStyle.css"/>
        <link rel="stylesheet" type="text/css" href="css/footerStyle.css"/>
        <link rel="stylesheet" type="text/css" href="css/TinTucStyle.css"/>
    </head>
    <body>      
        <div id="wrapper">
        <div id="backgroundBanner">
            <div id="header">                
                    <div id="logo">
                        <a href="index.php"><img src='img/logo.png'></a>
                    </div><!--end logo wrap-->
                    <div id="navigation"> 
                        
                        <ul class="Nav">
                            <li id="corp"><a href="corp.php">Silver Moon</a></li>
                            <li id="tintuc" class="selected"><a href="tintuc.php">Tin tức</a></li>
                            <li id="bacmattrang99"><a href="bacmattrang.php">Bạc mặt trăng 99.99</a></li>
                            <li id="dautu"><a href="dautu.php">Đầu tư bạc</a></li>
                            <li id="timhieu"><a href="timhieu.php">Tìm hiểu về bạc</a></li>
                            <li id="lienhe"><a href="lienhe.php">Liên hệ</a></li>
                        </ul>
                    </div>
                    
            </div>
            <div id="bannerContent">
                <div id="titlePage">Tin tức Bạc Mặt Trăng</div>
                <div id="menuNewsPage">
                    <?php
                    include "DB.php";
                   $result1 = mysql_query("SELECT type,id from newstype");
                   while ($row = mysql_fetch_row($result1))
                   {
                       $type = $row[0];
                       $id = $row[1];
                       echo  "<a href='tintuc.php?id=$id'>$type</a>";
                   };
                   ?>
                </div>
            </div>
        </div> <!-- End backgroundBanner -->
        
        <!-- -->
        
        <div id="mainContent">
            <div id="topHeaderContent"><h1>Tin tức tổng hợp</h1></div>
            <div id="hotNewsContent">
                <?php 
                    if (isset($_GET['id']))
                    {
                        $id_type = $_GET['id'];
                        $result = mysql_query(" SELECT news.ID,title,description,content,image,news.type,newstype.type,time 
                                            FROM news,newstype WHERE news.type = newstype.ID AND newstype.id = $id_type");
                    }
                    else {
                        $result = mysql_query(" SELECT news.ID,title,description,content,image,news.type,newstype.type,time 
                                            FROM news,newstype WHERE news.type = newstype.ID ");
                    }
                    
                    //$checkBlock = false;
                    while ($row = mysql_fetch_row($result))
                    {
                        $i = 375;
                        $id_news = $row[0];
                        $title = $row[1];
                        $des = $row[2];
                        $length = strlen($des);
                        $showDes = substr($des,0, $i - intval($length));
                        while (substr($showDes, -1) != ' ')
                        {
                            $i = $i - 1;
                            $showDes = substr($des,0, $i - intval($length));
                        }
                        $showDes = $showDes.'...';
                       // $content = $row[3];
                        $image = $row[4];
                       // $typeID = $row[5];
                        $type = $row[6];
                        $time = $row[7];
                        $hour = date("H:i",strtotime($time));
                        $date = date("d/m/Y",strtotime($time));
                        echo 
                        "<div id='News' class='News blockA'>
                            <div id='imgNews' class=''>
                                <img id='img1' class='imgNews' src='$image' alt='IMG'>
                            </div>
                            <div id='sumNews' class='sumNews'>
                                <div id='titleNews' class='titleNews'>
                                    <h3>$title</h3>
                                    <span>$hour | $date</span><br>
                                </div>";
                        if ($length >= $i)
                        {
                          echo "      <div id='contentNews' class='contentNews'>$showDes
                                    <a id='ViewDetail' class='linkViewDetail'> >> Chi tiết</a>
                                </div>
                            </div>
                        </div> ";}
                        else
                        {
                             echo "      <div id='contentNews' class='contentNews'>$des
                                    <a id='ViewDetail' class='linkViewDetail'> >> Chi tiết</a>
                                </div>
                            </div>
                        </div> ";
                        }
                        
                    }
                ?>
            </div>
        </div>
            <?php include "footer.php" ?>
        </div>
    </body>
</html>
